package com.cqtczh.qhd.driver.acticity.carteam;

import httptools.HttpJsonTool;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.cqtczh.qhd.driver.AppContent;
import com.cqtczh.qhd.driver.R;
import com.cqtczh.qhd.driver.acticity.base.BaseActivity;
import com.cqtczh.qhd.driver.api.GagApi;
import com.cqtczh.qhd.driver.vo.JsonRequest;
import com.cqtczh.qhd.driver.vo.JsonResponse;
import com.cqtczh.qhd.driver.vo.State;

/**
 * * @author 作者 陈修园:
 * 
 * @date 创建时间：2015-5-7 下午2:52:58
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class Activity_Creat_Car_Team extends BaseActivity implements
		OnClickListener {

	Button Creat;
	
	EditText CarTeamName;
	EditText car_team_describe;
	AppContent app;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_craet_car_team);
		Ini();
	}

	private void Ini() {
		TextView  headTite=(TextView) findViewById(R.id.head_title);
		headTite.setText("创建车队");
		ImageView headview=(ImageView) findViewById(R.id.head_left);
		headview.setVisibility(View.VISIBLE);
		headview.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Activity_Creat_Car_Team.this.finish();
			}
		});
		Creat = (Button) findViewById(R.id.new_set_button);
		
		CarTeamName = (EditText) findViewById(R.id.car_team_name);
		car_team_describe = (EditText) findViewById(R.id.car_team_describe);
		Creat.setOnClickListener(this);
	//	CarTeamName.setOnClickListener(this);
	//	car_team_describe.setOnClickListener(this);
		app = (AppContent) getApplication();
	}

	private void CreatCarTeam(String car_team_name, String car_team_company) {

		Map<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("leaderid", app.userId);
		dataMap.put("motorcadename", car_team_name);
		dataMap.put("motorcadedescription", car_team_company);
		HttpJsonTool httpJsonTool=new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler(){
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what==1) {
					Toast.makeText(Activity_Creat_Car_Team.this,(String)msg.obj, Toast.LENGTH_LONG).show();
					Activity_Creat_Car_Team.this.finish();
				}else {
					Toast.makeText(Activity_Creat_Car_Team.this,(String)msg.obj, Toast.LENGTH_LONG).show();
				}
			}
		});//http://192.168.1.111:8080/cqtczh/moduls/fleets/isLogin.do
		httpJsonTool.StartWork(dataMap, GagApi.CREAT_CAR_TEAM, null, null);
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.new_set_button:
			String c_name = CarTeamName.getText().toString();
			String c_comp = car_team_describe.getText().toString();
			if (c_comp.length() == 0) {
				c_comp = "";
			}
			if (c_name.length() > 0) {
				CreatCarTeam(c_name, c_comp);
			} else {
				Toast.makeText(Activity_Creat_Car_Team.this, "请输入车队名称",
						Toast.LENGTH_LONG).show();
			}
			break;

		default:
			break;
		}
	}
}
